#include <cstdio>
#include <iostream>
#include <map>
using namespace std;

int n;
string s1,s2;
map <string,int> m;

bool check(string s)
{
	int p = 0,len = s.length(),t;
	
	for(int i = 1;i <= 4;i++)
	{
		t = 0;
		if(s[p] < '0' || s[p] > '9') return false;
		if(s[p] == '0' && '0' <= s[p + 1] && s[p + 1] <= '9')  return false;
		while(p < len && '0' <= s[p] && s[p] <= '9')
		{
			t = t * 10 + s[p] - '0';
			p++;
			if(t > 255) return false;
		}
		if(p >= len - 1) return false;
		if(i != 4 && s[p] != '.') return false;
		if(i == 4 && s[p] != ':') return false;
		p++;
	}
	
	t = 0;
	if(s[p] == '0' && p != len - 1)  return false;
	while(p < len && '0' <= s[p] && s[p] <= '9')
	{
		t = t * 10 + s[p] - '0';
		p++;
		if(t > 65535) return false;
	}
	if(p != len) return false;
	
	return true;
}

int main()
{
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	
	scanf("%d",&n);
	for(int i = 1;i <= n;i++)
	{
		cin >> s1 >> s2;
		if(s1 == "Server")
		{
			if(check(s2))
			{
				if(m[s2]) printf("FAIL\n");
				else
				{
					m[s2] = i;
					printf("OK\n");
				}
			}
			else printf("ERR\n");
		}
		else
		{
			if(check(s2))
			{
				if(!m.count(s2)) printf("FAIL\n");
				else printf("%d\n",m[s2]);
			}
			else printf("ERR\n");
		}
	}
	
	return 0;
}
